<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">课程审核管理</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>课程审核管理</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            <div class="layui-input-inline">
                <input id="courseUser-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>
            </div>
            <div class="layui-input-inline layui-form">
                <select name="state" id="stateSearch">
                    <option value="0">全部</option>
                    <option value="1">审核中</option>
                    <option value="2">通过</option>
                    <option value="3">不过</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <button id="courseUser-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
            </div>
        </div>

        <table class="layui-table" id="courseUser-table" lay-filter="courseUser-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="courseUser-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
</script>


<script>
    layui.use(['form', 'index','table', 'util', 'config', 'admin'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;

        // 渲染表格
        table.render({
            elem: '#courseUser-table',
            url: config.base_server + 'api-course/courseUser/getSelectCourseUsers'+'?access_token='+config.getToken().access_token,
            method: 'post',
            where: {
                 // access_token: config.getToken().access_token
            },
            page: true,
            cols: [[
                {type: 'numbers'},
                {field: 'courseTitle', sort: true, title: '课程名称'},
                {field: 'choiceName', sort: true, title: '选课者'},
                {field: 'state', sort: true, title: '审核状态',
                templet: function (data) {
                    if (data.state === 1) {
                        return data.state = "<font color='#663399'>审核中</font>"
                    } else if (data.state === 2) {
                        return data.state = "<font color='green'>通过</font>"
                    } else {
                        return data.state = "<font color='red'>不过</font>"
                    }
                }},
                {field: 'createTime',
                    sort: true, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '创建时间'
                },
                {align: 'center', toolbar: '#courseUser-table-bar', title: '操作',width: 150}
            ]]
        });

        // 工具条点击事件
        table.on('tool(courseUser-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            }
        });

        // 搜索按钮点击事件
        $('#courseUser-btn-search').click(function () {
            var value = $('#courseUser-search-value').val();
            table.reload('courseUser-table', {where: {searchKey: value,state: $("#stateSearch").val()}});
        });

        //显示修改表单弹窗
        var showEditModel = function (data) {
            admin.putTempData('courseUser', data);
            var title = '修改课程类型';
            admin.popupCenter({
                title: title,
                path: 'pages/course/courseUser_form.html',
                finish: function () {
                    table.reload('courseUser-table', {});
                }
            });
        };

    });


</script>